<?php
class RuaBSN extends GenericBSN {

	function __construct() {
		$this->dao = new RuaDAO();		
	}

	public function consultar($vars) {
		$this->preencher($vars);
		$this->Records = $this->dao->consultar($this->where, $this->params, $this->order . $this->limit);
		$this->Result  = "OK";
	}
	
	public function consultarPK($vars) {
		$this->Records = $this->dao->consultarPK($vars['id']);
		$this->Result = "OK";
	}
	
	public function consultarSQ($vars) {
		$where = "where sq_id = :sq_id and rua like :rua";
		$params['sq_id'] = $vars['sq_id'];
		$params['rua']   = $vars['rua'] . '%';
		$this->Records   = $this->dao->consultar($where, $params);
		$this->Result    = "OK";
	}
	
	public function inserir($vars) {
		$registro['rua']		 = $vars['rua'];
		$registro['linha'] 		 = $vars['linha'];
		$registro['superquadra'] = $vars['sq_id'];
		
		try {
			$this->Record = $this->dao->inserir($registro);
			$this->Result  = "OK";
		} catch (Exception $e) {
			$this->Result  = "ERROR";
			$this->Message = "Erro ao tentar inserir: " . $e->getMessage();
		}
	}
	
	public function alterar($vars) {
		$registro['id'] 	 	= $vars['id'];
		$registro['rua']		 = $vars['rua'];
		$registro['linha'] 		 = $vars['linha'];
		$registro['superquadra'] = $vars['sq_id'];
				
		try {		
			$this->Record = $this->dao->alterar($registro); 
			$this->Result  = "OK";
		} catch (Exception $e) {
			$this->Result  = "ERROR";
			$this->Message = "Erro ao tentar alterar: " . $e->getMessage();
		}
	}
	
	public function excluir($registro) {
		try {
			$res = $this->dao->excluir($registro['id']);
			$this->Result  = "OK";
		} catch (Exception $e) {
			$this->Result  = "ERROR";
			$this->Message = "Erro ao tentar excluir: " . $e->getMessage();
		}
	}
}
?>